#include "Precompiled.h"
#include "GraphicsPipeline9.h"

namespace Game {
namespace GraphicsPipeline {

GraphicsPipeline9::GraphicsPipeline9(IDirect3DDevice9* pd3dDevice) : d3dDevice(pd3dDevice) {
    DXUTSetCallbackD3D9DeviceReset(GraphicsPipeline9::D3D9DeviceResetCallback, this);
    DXUTSetCallbackD3D9FrameRender(GraphicsPipeline9::D3D9FrameRenderCallback, this);
    DXUTSetCallbackD3D9DeviceLost(GraphicsPipeline9::D3D9DeviceLostCallback, this);
}

GraphicsPipeline9::~GraphicsPipeline9() {
    DXUTSetCallbackD3D9DeviceReset(NULL);
    DXUTSetCallbackD3D9FrameRender(NULL);
    DXUTSetCallbackD3D9DeviceLost(NULL);
}

void GraphicsPipeline9::Finalize() {

}

void GraphicsPipeline9::Initialize() {

}

void GraphicsPipeline9::FrameRender(IDirect3DDevice9* pd3dDevice, const double& fTime, const float& fElapsedTime) {
    HRESULT hr;

    // Clear the render target and the zbuffer
    V(pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170), 1.0f, 0));

    // Render the scene
    if (SUCCEEDED(pd3dDevice->BeginScene())) {
        V( pd3dDevice->EndScene() );
    }
}

void GraphicsPipeline9::OnDeviceLost() {
}

HRESULT GraphicsPipeline9::OnDeviceReset(IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc) {
    return S_OK;
}

void CALLBACK GraphicsPipeline9::D3D9DeviceLostCallback(void* pUserContext) {
    return static_cast<GraphicsPipeline9*>(pUserContext)->OnDeviceLost();
}

HRESULT CALLBACK GraphicsPipeline9::D3D9DeviceResetCallback(IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext) {
    return static_cast<GraphicsPipeline9*>(pUserContext)->OnDeviceReset(pd3dDevice, pBackBufferSurfaceDesc);
}

void CALLBACK GraphicsPipeline9::D3D9FrameRenderCallback(IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext) {
    return static_cast<GraphicsPipeline9*>(pUserContext)->FrameRender(pd3dDevice, fTime, fElapsedTime);
}

}
}
